<template>
  <div class="eventLevel" style="height: calc(100%-63px);">
    <CommonBtn label-name="客户审核关闭查看" v-if="!showEdit" :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked && item.label && item.valueName != undefined">{{item.label+":"+item.valueName}}</span>
    </CommonBtn>
    <CommonList v-if="!showEdit" :buttons="buttons" :columns="columns" :conditions="conditions" :listUrl="$api.API_SMMS_NOSAP_ClOSE_LIST" @tableSelect="tableSelect" @dbClick="openItem"></CommonList>
    <CustomerEdit :pageType="pageType"
                  ref="commonEdit"
                  :disabled="!enableEdit"
                  :label="editTitle"
                  v-if="showEdit"
                  :items="items"
                  :originalData="row"
                  @editBack="editBack"
                  />
    <CommonSearch :label="item.label"
                  :conditions="item.conditions"
                  v-for="(item, index) of searchs"
                  :key="index"
                  :listUrl="item.listUrl"
                  :columns="item.columns"
                  :items="item.items"
                  :page="item.page"
                  :originalData="item.searchData"
                  @submit="item.selectItem"
                  @searchBack="searchBack"/>

    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_NOSAPSMMSDEALER_EXPORT" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import CustomerEdit from "./CustomerEdit";
    import CommonExport from "../../common/CommonExport";
    import CommonSearch from '../../common/CommonSearch'
    export default {
        name:'noSAPClosedCustomerQuery',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                searchData: {},
                searchItems: [],
                searchs:[],
                showEdit: false,
                editTitle: '查看客户信息',
                enableEdit: false,
                row: null,
                pageType: -1,
                conditions: [],
                columns:[
                    {
                        prop:'smmsCode',
                        label:'统一编码'
                    },
                    {
                        prop:'smmsName',
                        label:'客户名称'
                    },
                    {
                        prop:'levelName',
                        label:'客户属性'
                    },
                    {
                        prop:'dataSource',
                        label:'数据来源'
                    },
                    {
                        prop:'smmsOwnerName',
                        label:'供货方名称'
                    },
                    {
                        prop:'changeStatus',
                        label:'变更审核状态'
                    },
                    {
                        prop:'cooperationStatus',
                        label:'合作状态'
                    },
                    {
                        prop:'buName',
                        label:'业务单位'
                    },
                    {
                        prop:'customNameCN',
                        label:'客户集团'
                    },
                    {
                      prop:'isLKAvalue',
                      label:'是否LKA'
                    },
                    {
                        prop:'brandName',
                        label:'适用品牌'
                    },
                    {
                        prop:'province',
                        label:'省',
                        minWidth: 50
                    },
                    {
                        prop:'physicalCity',
                        label:'市',
                        minWidth: 50
                    },
                    {
                        prop:'adminCity',
                        label:'区县',
                        minWidth: 50
                    },
                    {
                        prop:'deAddress',
                        label:'详细地址'
                    },
                    {
                        prop:'repName',
                        label:'负责人'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                button:null,
                items: [{
                    name: '统一编码',
                    key: 'smmsCode',
                    type: 'text',
                    disable: true,
                    required: true,
                    placeholder: '系统自动生成'
                  },
                  {
                    name: '客户属性',
                    key: 'levelName',
                    vkey: 'fkDealerLevel',
                    type: 'single-select',
                    required: true,
                    options: []
                  },
                  {
                    name: 'SoldToCode(客户编码)',
                    key: 'soldToCode',
                    type: 'checktext',
                    required: true,
                    disable: false,
                    placeholder: '',
                    checkname: '是否自动生成'
                  },
                  {
                    name: '客户名称',
                    key: 'smmsName',
                    type: 'text',
                    placeholder: '',
                    required: true
                  },
                  {
                    name: '地理城市',
                    key: 'city',
                    type: 'multi-select',
                    required: false,
                    optionss: [{
                      options: [],
                      key: 'province'
                    }, {
                      options: [],
                      key: 'physicalCity'
                    }, {
                      options: [],
                      key: 'adminCity'
                    }]
                  },
                  {
                    name: '城市类别',
                    key: 'cityTypeName',
                    vkey: 'fkCityType',
                    type: 'single-select',
                    required: false,
                    disable: true,
                    options: []
                  },
                  {
                    name: '详细地址',
                    key: 'deAddress',
                    type: 'multi-text',
                    required: false,
                    texts: [{
                      key: 'address',
                      name: '街道',
                      span: 12
                    }, {
                      key: 'address1',
                      name: '路',
                      span: 12
                    }, {
                      key: 'address2',
                      name: null,
                      span: 24
                    }]
                  },
                  {
                    name: '客户负责人',
                    key: 'repName',
                    type: 'search',
                    required: true,
                    disable: false
                  },
                  {
                    name: '关联供货方',
                    key: 'smmsOwnerName',
                    type: 'search',
                    required: false,
                    disable: false
                  },
                  {
                    name: '供货方代码',
                    key: 'smmsSoldToCode',
                    type: 'text',
                    required: false,
                    disable: true
                  },
                  {
                    name: '业务单位',
                    key: 'buName',
                    vkey: 'fkBu',
                    type: 'single-select',
                    required: false,
                    disable: true,
                    options: []
                  },
                  {
                    name: '客户集团',
                    key: 'customNameCN',
                    type: 'search',
                    required: true,
                    disable: true
                  },
                  {
                    name: '是否LKA',
                    key: 'isLKAvalue',
                    vkey: 'isLKA',
                    type: 'single-select',
                    required: true,
                    disable: false,
                    placeholder: '请选择',
                    options: []
                  },
                  {
                    name: '适用品牌',
                    key: 'brandName',
                    vkey: 'fkBrand',
                    type: 'single-select',
                    required: true,
                    disable: true,
                    options: []
                  },
                  {
                    name: 'Destination',
                    key: 'destinationName',
                    vkey: 'fkDestination',
                    type: 'single-select',
                    required: false,
                    disable: true,
                    options: []
                  },
                  {
                    name: '客户联系人',
                    key: 'linkMan',
                    type: 'text',
                    placeholder: ''
                  },
                  {
                    name: '联系人手机',
                    key: 'linkPhone',
                    type: 'text',
                    placeholder: ''
                  },
                  {
                    name: '邮箱地址',
                    key: 'linkEmail',
                    type: 'text',
                    placeholder: '多个邮箱请用英文,(逗号分割)'
                  },
                  {
                    name: '申请费用状态',
                    key: 'tpFeeStatus',
                    type: 'single-select',
                    disable: false,
                    options: []
                  },
                  {
                    name: '客户营业状态',
                    key: 'businessStatus',
                    type: 'single-select',
                    disable: false,
                    options: []
                  },
                  {
                    name: '合作状态',
                    key: 'cooperationStatus',
                    type: 'single-select',
                    disable: false,
                    options: []
                  },
                  {
                    name: 'TPWF客户编码',
                    key: 'tpCode',
                    type: 'text',
                    required: false,
                    disable: true
                  },
                  {
                    name: 'JDES Code',
                    key: 'jdesCode',
                    type: 'text',
                    required: false,
                    disable: true
                  },
                ],
            }
        },
        methods:{
            onButtonClick(item) {
              let self = this
              if (item.event == 'search()') {
                this.searchs.push({
                  label: '查询客户信息',
                  page: 'customer',
                  searchData: this.searchData,
                  items: this.searchItems,
                  selectItem: function (formData, items) {
                    self.searchs.pop()
                    self.searchItems = items;
                    self.searchData = formData;
                    let data = {}
                    let conditions = self.conditions.filter(item=>{
                      return !item.label
                    })
                    // 回调
                    for (let idx in items) {
                      let item = items[idx]
                      if (item.checked == true) {
                        if (item.vkey) {
                          data[item.vkey] = formData[item.vkey]
                        } else {
                          data[item.key] = formData[item.key]
                        }
                        conditions.push({
                          checked: true,
                          label: item.name,
                          prop: item.vkey ? item.vkey : item.key,
                          valueName: formData[item.key],
                          value: item.vkey ? formData[item.vkey] : formData[item.key]
                        })
                      }
                    }
                    self.conditions = conditions
                  },
                })
              }
                this.button = item
            },
            tableSelect(row) {
              this.row = row
            },
            openItem(item) {
              // 打开详情
              this.showEdit = true
              this.enableEdit = false
            },
            searchBack() {
              this.searchs.pop()
            },
            editBack() {
              this.showEdit = false
            },
            close(item) {
                this.button = item
            }
        },
        watch: {
          showEdit(newVal,oldVal) {
            if (!newVal && oldVal) {
              this.conditions = this.conditions.map(item=>{return item})
            }
          }
        },
        components:{CommonExport,CommonList, CommonBtn, CustomerEdit, CommonSearch}
    }
</script>
